package com.masterrabbit.mcslf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.common.security.utils.SecurityUtils;
import com.masterrabbit.mcslf.pojo.Orders;
import com.masterrabbit.mcslf.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrdersService ordersService;
    @RequestMapping("/getbynumber/{number}")
    public AjaxResult testOrser(@PathVariable String number){
        QueryWrapper<Orders> ordersQueryWrapper = new QueryWrapper<>();
        ordersQueryWrapper.lambda().eq(Orders::getOrderNumber,number);
        Orders one = ordersService.getOne(ordersQueryWrapper);
        System.out.println(one.toString());
        return AjaxResult.success(one);
    }
//    确认核销接口 （）
@RequestMapping("/Verification/{verifiCode}")
    public AjaxResult Verification(@PathVariable String verifiCode, HttpServletRequest request){
    String currentStore = request.getHeader("CurrentStore");
     ordersService.Verification(verifiCode,currentStore);
     return AjaxResult.success();
    }
    @RequestMapping("/recode/page")
    public AjaxResult getrecodePage(@RequestBody Map<String, Object> pageparams){
        System.out.println(pageparams.toString());
//        Page<Orders> ordersPage = new Page<>();
        IPage<Orders> ordersPage  =  ordersService.getrecodePage(pageparams);
        return AjaxResult.success(ordersPage);
    }
}
